/*
 * File:   Player.cpp
 * Copyright (C) 2009
 *		Sergio Padrino Recio (PadrinatoR)
 *
 * Created on 19 de marzo de 2009, 0:13
 *
 * This file is part of BombProject.
 *
 * BombProject is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * BombProject is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with BombProject.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "Player.h"

Player::Player() : AnimatedSprite()
{
	mGameControl = NULL;
	mDirection = DIRECTION_DOWN;
}

Player::~Player(){

}

void Player::updateInput()
{
	//Player movement
	mSpeedX = mSpeedY = 0;

	if(mGameControl->getButtonState(BUTTON_DOWN)->button_held)
	{
		turnDown();
		moveDown();
	}
	else if(mGameControl->getButtonState(BUTTON_UP)->button_held)
	{
		turnUp();
		moveUp();
	}

	if(mGameControl->getButtonState(BUTTON_LEFT)->button_held)
	{
		turnLeft();
		moveLeft();
	}
	else if(mGameControl->getButtonState(BUTTON_RIGHT)->button_held)
	{
		turnRight();
		moveRight();
	}


	if(mGameControl->getButtonState(BUTTON_FIRE)->button_held && canPutBombs())
		putBomb();
}

void Player::update()
{
	mX += mSpeedX;
	mY += mSpeedY;
}

void Player::moveUp()
{
	mSpeedY = -mSpeed;
}

void Player::moveDown()
{
	mSpeedY = mSpeed;
}

void Player::moveLeft()
{
	mSpeedX = -mSpeed;
}

void Player::moveRight()
{
	mSpeedX = mSpeed;
}

void Player::turnUp()
{
	if(mDirection == DIRECTION_UP) return;

	mDirection = DIRECTION_UP;
	setAnimation("walking_up");
	playAnimation();
}

void Player::turnDown()
{
	if(mDirection == DIRECTION_DOWN) return;

	mDirection = DIRECTION_DOWN;
	setAnimation("walking_down");
	playAnimation();
}

void Player::turnLeft()
{
	if(mDirection == DIRECTION_LEFT) return;

	mDirection = DIRECTION_LEFT;
	setAnimation("walking_left");
	playAnimation();
}

void Player::turnRight()
{
	if(mDirection == DIRECTION_RIGHT) return;

	mDirection = DIRECTION_RIGHT;
	setAnimation("walking_right");
	playAnimation();
}
